using System.Data;
using System.Data.SqlClient;
using VanTaiProperty;
namespace VanTaiData
{
    public class clsTMDeliveryController
    {
        private clsConnect cls = new clsConnect();
        private DataTable dt;
        #region[Get-Data]
        public DataTable BindGirdTMDelivery()
        {
            return cls.BindGridData("sp_TMDelivery");
        }
        public DataTable BindGirdTMDelivery_Detail_Edit(int id)
        {
            return cls.LayDuLieuParameter("sp_TMDelivery_Detail_Edit","@Id", id);
        }
        #endregion

        #region[Insert-Delete-Update]
        public bool InsertTMDelivery(clsTMDeliveryProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Delivery_Alias", data.Delivery_Alias);
            cls.AddParameter("@Delivery_Name", data.Delivery_Name);
            cls.AddParameter("@Delivery_Note", data.Delivery_Note);
            cls.ExecuteNonQuery("sp_TMDelivery_Insert");
            return true;
        }
        public bool UpdateTMDelivery(clsTMDeliveryProperty data)
        {
            cls.CreateNewSqlCommand();
            cls.AddParameter("@Delivery_ID", data.Delivery_ID);
            cls.AddParameter("@Delivery_Alias", data.Delivery_Alias);
            cls.AddParameter("@Delivery_Name", data.Delivery_Name);
            cls.AddParameter("@Delivery_Note", data.Delivery_Note);
            cls.ExecuteNonQuery("sp_TMDelivery_Update");
            return true;
        }
        public bool DeleteTMDelivery(int id)
        {
            cls.Delete("sp_TMDelivery_Delete","@Delivery_ID", id);
            return true;
        }
        #endregion

        #region[Search-Fillter]
        public DataTable Search(string keywords)
        {
            return cls.Search("sp_TMDelivery_Search", "@KEYWORDS", keywords);
        }
        #endregion

        public bool TMDelivery_Check_Delete_TMCommandTransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMDelivery_Check_Delete_TMCommandTransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMDelivery_Check_Delete_TMPlan_TransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMDelivery_Check_Delete_TMPlan_TransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMDelivery_Check_Delete_TMSalesReport(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMDelivery_Check_Delete_TMSalesReport", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
        public bool TMDelivery_Check_Delete_TMDiaryTransferOrder(int id)
        {
            dt = cls.LayDuLieuParameter("sp_TMDelivery_Check_Delete_TMDiaryTransferOrder", "@Id", id);
            if (dt.Rows.Count > 0)
                return true;
            return false;
        }
    }
}